//
//  HasSharesViewController.m
//  Item
//
//  Created by 刘炳举 on 12/19/15.
//  Copyright © 2015 Kelly. All rights reserved.
//

#import "HasSharesViewController.h"
#import "NGRightTableViewViewController.h"
@interface HasSharesViewController (){
    NGRightTableViewViewController*rttv;
    BOOL isSelect;
    NSMutableArray *mArray;
    UIImageView* image;
    UIButton* changeBtn;
}

@end

@implementation HasSharesViewController
@synthesize rtvv;
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.topItem.title =@"股票持仓";
    // Do any additional setup after loading the view.
    
    mArray = [[NSMutableArray alloc] initWithObjects:@"s:99102-075",@"222",@"333",@"444",@"555", nil];
    
    UIView *rightButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];

    changeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 88, 30)];
    [changeBtn setTitle:@"s:99102-075" forState:UIControlStateNormal];
    changeBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
    [rightButtonView addSubview:changeBtn];

    [changeBtn addTarget:self action:@selector(rightBarBtnClicked) forControlEvents:UIControlEventTouchUpInside];

    image = [[UIImageView alloc] initWithFrame:CGRectMake(88,8,12,15)];
    [image setImage:[UIImage imageNamed:@"down_dark.png"]];
    [image setContentMode:UIViewContentModeScaleToFill];

    [rightButtonView addSubview:image];
    //把右侧的两个按钮添加到rightBarButtonItem
    UIBarButtonItem *rightCunstomButtonView = [[UIBarButtonItem alloc] initWithCustomView:rightButtonView];
    self.navigationItem.rightBarButtonItem = rightCunstomButtonView;

    if (!rtvv) {
        rtvv = [[NGRightTableViewViewController alloc]init];
    }
    rtvv.tableViewArray = mArray;
    rtvv.view.frame = CGRectMake(self.view.frame.size.width-120,43,100,120);
    [self addChildViewController:rtvv];
    [self.view addSubview:rtvv.view];
    rtvv.pulldelegate = self;
    [rtvv.view setHidden:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)rightBarBtnClicked{
    if (!isSelect) {
        [rtvv.view setHidden:NO];
        isSelect=YES;
         image.transform=CGAffineTransformMakeRotation(M_PI);
    }else{
        [rtvv.view setHidden:YES];
        isSelect=NO;
        image.transform=CGAffineTransformMakeRotation(0);
    }
    
}
#pragma mark - pulldelegate
-(void)menuItemSelected:(NSIndexPath *)indexPath{
    NSLog(@"selectAcc:%@",[mArray objectAtIndex:indexPath.item]);
    [rtvv.view setHidden:YES];
    isSelect=NO;
    image.transform=CGAffineTransformMakeRotation(0);
    changeBtn.titleLabel.text = [mArray objectAtIndex:indexPath.item];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
